home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 42 / Amiga Format AFCD42 (Issue 126, Aug 1999).iso / -serious- / programming / basic / blitzandpieces / sierpiƱski.asc < prev    next >
Encoding:
Text File  |  1999-05-14  |  1.3 KB  |  67 lines

  1. ;                               ~
  2. ; Statement which plots a Sierpinski triangle in a Workbench window.
  3.  
  4. ; Left mouse button quits.
  5.  
  6. ; Adapted from Conrad Bessant's "Computers and Chaos" book,
  7. ; AmigaBASIC listing by Conrad Bessant.
  8.  
  9. ; James L Boyd - jamesboyd@all-hail.freeserve.co.uk
  10.  
  11. ; totally useless, but cool :)
  12.  
  13. WbToScreen 0 ; gimme the wb screen
  14.  
  15. NoCli
  16.  
  17. *scr.Screen=Peek.l(Addr Screen(0)) ; get screen pointer
  18.  
  19. ScreenToFront_ *scr ; show it
  20.  
  21. Window 0,0,*scr\BarHeight+1,*scr\Width,*scr\Height-(*scr\BarHeight+1),$1800,"",1,2
  22.  
  23. NPrint ""
  24. NPrint "  Sierpi"+Chr$(241)+"ski Triangle"
  25.  
  26. *rp.RastPort=RastPort (0)
  27.  
  28. Statement PlotTri {x1.w,x2.w,x3.w,y1.w,y2.w,y3.w}
  29.  
  30. ;         PlotTri { centre, left, right, top, left bottom, right bottom }
  31.  
  32.   SHARED *rp.RastPort ; use the rastport we got earlier
  33.  
  34.   Dim x.w(2),y.w(2)
  35.  
  36.   x(0)=x1
  37.   y(0)=y1
  38.   x(1)=x2
  39.   y(1)=y2
  40.   x(2)=x3
  41.   y(2)=y3
  42.  
  43.   vertex=Int(Rnd(3))
  44.   px=x(vertex)
  45.   py=y(vertex)
  46.  
  47.   While Joyb(0)=0
  48.  
  49.     vertex=Int(Rnd(3))
  50.     px=px+(x(vertex)-px)/2
  51.     py=py+(y(vertex)-py)/2
  52.  
  53.     SetAPen_ *rp,Int(Rnd(2^WBDepth)) ; choose random WB pen
  54.  
  55.     Move_ *rp,px,py ; remove for scary effect :)
  56.     Draw_ *rp,px,py
  57.  
  58.   Wend
  59.  
  60. End Statement
  61.  
  62. ; let's go for full-window :)
  63.  
  64. PlotTri {*scr\Width/2,0,*scr\Width,0,*scr\Height-(*scr\BarHeight+1),*scr\Height-(*scr\BarHeight+1)}
  65.  
  66. End
  67.